package data;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import fileProcessing.ParsingException;

public class BankAccountNumberEntry extends AbstractDataType<BankAccountNumberEntry>{
	
	private long bankAccountNumber;
	private String fieldType = "Bank Account";
	
	public BankAccountNumberEntry(){};
	
	public BankAccountNumberEntry(RandomAccessFile raf) throws ParsingException{
		try {
			bankAccountNumber = raf.readLong();
		} catch (IOException e) {
			throw new ParsingException("Error: "+e.getMessage()+" when reading date from table's data file");
		}
	}
	
	public BankAccountNumberEntry(String acctNum) throws ParsingException{
		if(isValid(acctNum)){
			bankAccountNumber = Long.parseLong(acctNum);
		}
		else
			throw new ParsingException("Phone number not valid.");
	}	

	public boolean isValid(String val){
		Pattern pattern = Pattern.compile("\\d{1,17}");
		Matcher matcher = pattern.matcher(val);
		return matcher.matches();
	}

	@Override
	public int compareTo(BankAccountNumberEntry o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType() {
		return fieldType;
	}
}
